package net.anzhuo.controller.db.report;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import lombok.extern.slf4j.Slf4j;
import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.common.utils.RedisUtil;
import net.anzhuo.entity.GsYichang;
import net.anzhuo.entity.db.yichang.ResponseResult;
import net.anzhuo.entity.db.yichang.Result;
import net.anzhuo.service.GsYichangService;

@RestController
@Slf4j
public class YichangController {

	@Autowired
	private GsYichangService gsYichangService;
	
	@RequestMapping("/report/yichang")
	public ResponseResult getYichang(String keyNo) {
		log.info("===>getYichang_keyNo="+keyNo);
		long startTime=System.currentTimeMillis();
		ResponseResult rr = null;
		try {
			rr = (ResponseResult)RedisUtil.get("report:yichang:"+keyNo);
			if (rr != null) {
				 long endTime=System.currentTimeMillis();
				 float excTime=(float)(endTime-startTime)/1000;
				 log.info(" report:yichang 执行时间："+excTime+"s");
				return rr;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		GsYichang gsYichang = new GsYichang();
		gsYichang.setCoMd5(keyNo);
		gsYichang.setPageSize(50);
		PaginationVO<GsYichang> yichangList = gsYichangService.getListWithPage(gsYichang);
		
		ResponseResult responseResult = new ResponseResult();
		responseResult.setStatus("200");
		responseResult.setMessage("查询成功");
		
		List<Result> resultList = new ArrayList<>();
		Result result = null;
		if (yichangList.getList()!=null && yichangList.getList().size()>0) {
			for (GsYichang y : yichangList.getList()) {
				result = new Result();
				result.setAddReason(y.getIncludeReason());
				result.setAddDate(y.getIncludeTime());
				result.setRomoveReason(y.getRemoveReason());
				result.setRemoveDate(y.getRemoveTime());
				result.setDecisionOffice(y.getDecisionOrg());
				result.setRemoveDecisionOffice(y.getRemoveOrg());
				resultList.add(result);
			}
		}
		responseResult.setResult(resultList);
		
		try {
			RedisUtil.set("report:yichang:"+keyNo, responseResult);
		} catch (Exception e) {
			e.printStackTrace();
		}
		 long endTime=System.currentTimeMillis();
		 float excTime=(float)(endTime-startTime)/1000;
		 log.info(" report:yichang 执行时间："+excTime+"s");
		return responseResult;
	}
}
